package com.linewow.xhyy.nihaonew.fragment.nav;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.cleveroad.slidingtutorial.OnTutorialPageChangeListener;
import com.cleveroad.slidingtutorial.TutorialOptions;
import com.cleveroad.slidingtutorial.TutorialPageProvider;
import com.cleveroad.slidingtutorial.TutorialSupportFragment;
import com.linewow.xhyy.nihaonew.R;

/**
 * Created by LXR on 2016/11/9.
 */
public class StartFragment extends TutorialSupportFragment implements OnTutorialPageChangeListener {

    private String TAG = "StartFragment";

    private int[] pagesColors;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (pagesColors == null) {

            pagesColors = new int[]{
                    ContextCompat.getColor(getContext(), android.R.color.white),
                    ContextCompat.getColor(getContext(), android.R.color.white),
                    ContextCompat.getColor(getContext(), android.R.color.white),
                    ContextCompat.getColor(getContext(), android.R.color.white),
            };
        }
        addOnTutorialPageChangeListener(this);
    }

    @Override
    public void onPageChanged(int position) {

        Log.e(TAG, "位置onPageChanged" + position);
    }


    private final View.OnClickListener mOnSkipClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getContext(), "Skip button clicked", Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected TutorialOptions provideTutorialOptions() {

        return newTutorialOptionsBuilder(getContext())
//                .setUseInfiniteScroll(true)
                .setPagesColors(pagesColors)
                .setPagesCount(4)
                .setTutorialPageProvider(mTutorialPageProvider)
//                .setIndicatorOptions(IndicatorOptions.newBuilder(getContext())
//                        .setElementSizeRes(R.dimen.indicator_size)
//                        .setElementSpacingRes(R.dimen.indicator_spacing)
//                        .setElementColorRes(android.R.color.darker_gray)
//                        .setSelectedElementColor(Color.LTGRAY)
//                        .setRenderer(RhombusRenderer.create())
//                        .build())
                .onSkipClickListener(mOnSkipClickListener)
                .build();
    }




    private final TutorialPageProvider<Fragment> mTutorialPageProvider=new TutorialPageProvider<Fragment>() {
        @NonNull
        @Override
        public Fragment providePage(int position) {
            switch (position){
                case 0:
                    return new FirstFragment();
                case 1:
                    return new SecondFragment();
                case 2:
                    return new ThirdFragment();
                case 3:
                    return new FourthFragment();
                default:{
                    throw new IllegalArgumentException("Unknown position: " + position);
                }
            }
        }
    };




    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_start;
    }
}